<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePayStream extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('pay_stream', function (Blueprint $table) {
            $table->char('payNo', 32)->default('')->comment("我方 唯一支付流水号");
            $table->unsignedBigInteger('orderId')->default(0)->comment('orders表id');
            $table->char('thirdPayNo', 32)->default('')->comment("三方 支付流水号");
            $table->unsignedTinyInteger('payStatus')->default(0)->comment("0未支付 1支付成功");
            $table->unsignedInteger('payPrice')->default(0)->comment("支付价格");
            $table->unsignedInteger('paySuccessTime')->default(0)->comment("支付成功时间");
            $table->unsignedTinyInteger('payChannel')->default(0)->comment("支付渠道 1支付宝直连 2微信直连 3现金 4富友");
            $table->unsignedTinyInteger('payAction')->default(0)->comment("支付操作类型 1用户主扫 2用户被扫 3 小程序支付");

            // 统一表字段
            $table->integer('createdAt')->default(0)->comment('创建时间');
            $table->integer('createdByUid')->default(0)->comment('创建人');
            $table->integer('updatedAt')->default(0)->comment('修改时间');
            $table->integer('updatedByUid')->default(0)->comment('修改人');

            // 索引部分
            $table->primary('payNo', 'idx_payNo');
            $table->index('orderId', 'idx_orderId');
            $table->index('thirdPayNo', 'idx_thirdPayNo');
            $table->index('createdAt', 'idx_createdAt');

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}pay_stream` COMMENT = '支付流水表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('pay_stream');
    }
}
